import express from 'express';
const router = express.Router();
import createError from 'http-errors';
import mfun from '../utils/common-mu.js';
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url); 
const __dirname = path.dirname(__filename);

await mfun.loadRouter({
	router,
	dirname: __dirname
})

/* GET home page. */
router.get('/', function(req, res, next) {
	res.render('index', { title: 'Express' });
});

// catch 404 and forward to error handler
router.use(function(req, res, next) {
	next(createError(404));
});

// error handler
router.use(function(err, req, res, next) {
	// set locals, only providing error in development
	res.locals.message = err.message;
	res.locals.error = req.app.get('env') === 'development' ? err : {};

	// render the error page
	res.status(err.status || 500);
	res.render('error');
});

export default router;